package com.yyyzzz.servlet;

import com.yyyzzz.DAO.impl.teacherDaoimpl;
import com.yyyzzz.bean.Teacher;
import com.yyyzzz.service.impl.teacherServiceImpl;
import com.yyyzzz.service.teacherService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.List;
/*@WebServlet("/modify")*/
public class teacherModifyServlet extends HttpServlet {
    @Override
    protected void doGet (HttpServletRequest req , HttpServletResponse resp) throws ServletException, IOException {
        HttpSession session = req.getSession ();
        Teacher teacher = (Teacher) session.getAttribute ("teacher");
String name = req.getParameter ("teacherName");
String pwd = req.getParameter ("pwd");
String job = req.getParameter ("job");
String sex = req.getParameter ("sex");
        Teacher teacher1 = new Teacher ();
        teacher1.setTeacherNo (teacher.getTeacherNo ());
        teacher1.setTeachername (name);
        teacher1.setTeacherjob (job);
        teacher1.setTeacherpassword (pwd);
        teacher1.setSex (sex);
        session.setAttribute ("teacher",teacher1);
        teacherService service = new teacherServiceImpl();
        try {
            boolean flag = service.modifyTeacher (teacher1);
            if ( flag ){
             /*   teacherDaoimpl teacherDaoimpl = new teacherDaoimpl ();
                List list = teacherDaoimpl.getList (teacher.getTeacherNo ());*/
                resp.getWriter ().print ("修改成功!");
                req.getRequestDispatcher ("teacherself.jsp").forward (req,resp);
                int id = (int) session.getAttribute ("id");
                teacherDaoimpl teacherDaoimpl = new teacherDaoimpl ();
                List list = teacherDaoimpl.getList (id);
                req.setAttribute ("list",list);
                System.out.println ("这个是"+list);
         /*       req.setAttribute ("list",list);*/
            }else {
                resp.getWriter ().print ("修改失败！");
            }
        } catch (Exception e) {
            e.printStackTrace ();
        }
    }

    @Override
    protected void doPost (HttpServletRequest req , HttpServletResponse resp) throws ServletException, IOException {
        doGet (req , resp);
    }
}
